// default package
// Generated Jul 28, 2012 3:15:14 PM by Hibernate Tools 3.4.0.CR1
package cl.usm.taller.corona.dao;

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example;

import cl.usm.taller.corona.model.TiposEvaluacion;
import cl.usm.taller.corona.util.HibernateUtil;

/**
 * Home object for domain model class TiposEvaluacion.
 * @see .TiposEvaluacion
 * @author Hibernate Tools
 */
public class TiposEvaluacionDao {

	private static final Log log = LogFactory.getLog(TiposEvaluacionDao.class);




	public void persist(TiposEvaluacion transientInstance) {
		log.debug("persisting TiposEvaluacion instance");
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
	        session.beginTransaction();
	        session.save(transientInstance);
	        session.getTransaction().commit();	        
	        log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}
	public void attachDirty(TiposEvaluacion instance) {
		log.debug("attaching dirty TiposEvaluacion instance");
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.saveOrUpdate(instance);
			session.getTransaction().commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TiposEvaluacion instance) {
		log.debug("attaching clean TiposEvaluacion instance");
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.lock(instance, LockMode.NONE);
			session.getTransaction().commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Integer id) {
		log.debug("Delete TiposEvaluacion instance");
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
	        session.beginTransaction();
	        TiposEvaluacion TiposEvaluacion = (TiposEvaluacion) session.load(TiposEvaluacion.class, id);
	        if(null != TiposEvaluacion) {
	            session.delete(TiposEvaluacion);
	        }
	        session.getTransaction().commit();
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TiposEvaluacion merge(TiposEvaluacion detachedInstance) {
		log.debug("merging TiposEvaluacion instance");
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			TiposEvaluacion result = (TiposEvaluacion) session.merge(detachedInstance);
			session.getTransaction().commit();
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public TiposEvaluacion findById(java.lang.Integer id) {
		log.debug("getting TiposEvaluacion instance with id: " + id);
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			TiposEvaluacion instance = (TiposEvaluacion) session.get("TiposEvaluacion", id);
			session.getTransaction().commit();
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	
	public List<TiposEvaluacion> list() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
        List<TiposEvaluacion> tiposEvaluacion = null;
        try {
             
        	tiposEvaluacion = (List<TiposEvaluacion>)session.createQuery("from TiposEvaluacion").list();
             
        } catch (HibernateException e) {
            e.printStackTrace();
            session.getTransaction().rollback();
        }
        session.getTransaction().commit();
        return tiposEvaluacion;
    }
	
}
